package com.example.myapplication;

import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import java.util.ArrayList;
import java.util.Calendar;
import java.sql.Date;

public class PullRefresh extends AppCompatActivity {
  private RefreshLayout mRefreshLayout;
  private RecyclerView recyclerView;
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.refresh_layout);
    //Toolbar toolbar = findViewById(R.id.toolbar);
    //toolbar.setTitle("下拉刷新测试");
    //setSupportActionBar(toolbar);
    Init();

  }

  private void Init() {
    mRefreshLayout = findViewById(R.id.refreshLayout);
    recyclerView = findViewById(R.id.info_list);
    //mRefreshLayout.setEnableLoadMore(false);
    mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
      @Override public void onRefresh(RefreshLayout refreshLayout) {
        refreshLayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
      }
    });

    //mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
    //  @Override public void onLoadMore(RefreshLayout refreshLayout) {
    //    refreshLayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
    //  }
    //});



    ArrayList<Note> noteArrayList = new ArrayList<>();
    Note note = new Note("小哈", "1058161932", "呵呵鼠奴你又在骗我了吧");
    Note note2 = new Note("小哈", "1058161932", "呵呵鼠奴");
    note.setCreateTime(MakeDate(2020, 6, 23));
    note2.setCreateTime(MakeDate(2020, 6, 23));
    noteArrayList.add(note);
    noteArrayList.add(note2);
    NoteArrayListAdapter adapter = new NoteArrayListAdapter(noteArrayList);
    recyclerView.setAdapter(adapter);
    //需要设置布局管理器
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    ItemTouchHelper.Callback callback = new SwipeItemTouchHelperCallBack(adapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    System.out.println(note.getCreateTime());

  }

  private Date MakeDate(int year, int month, int day) {

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month-1, day);
    Date date = new Date(calendar.getTime().getTime());

    return date;
  }
}
